// pages/list/list.js
Page({

	/**
	 * 页面的初始数据
	 */
	data: {
		pg: 1,
		px: 0,
		http: getApp().globalData.map,
		pd: 1,
		xx: '',
		brand: 0,
		data:[]
	},


	onLoad: function(options) {
		this.setData({
			xx: options.xx,
			state: options.state
		})
		let pages = getCurrentPages(); // 当前页的数据，可以输出来看看有什么东西
		let prevPage = pages[pages.length - 2];
		if (prevPage.route == 'pages/brand/brand') {
			this.setData({
				brand: options.brand
			})
		}
	},
	zonghe(){
		this.setData({
			px:0,
			list: [],
			pg:1,
			zt: false
		}) 
		this.push()
	},
	onShow() {
		this.setData({
			xin: 1,
			pg:1,
			data:[]
		})
		if (this.data.state == 0) {
			this.push()
		} else {
			this.dp()
		}
	},
	dp() {
		wx.request({
			url: getApp().globalData.http + 'action=searchFactory&pg=' + this.data.pg + '&key=' + this.data.xx,
			success: (e) => {
				console.log(e)
				let a = this.data.data
				if (this.data.xin == 1) {
					a = []
				}
				for(let i in e.data.data) {
					a.push(e.data.data[i])
				}
				if (e.data.data.length < 15) {
					this.setData({
						pd: 0
					})
				}
				this.setData({
					data: a,
				})
			}
		})
	},
	push() {
		wx.request({
			url: getApp().globalData.http + 'action=searchCarYongping&classID=' + this.data.brand + '&key=' + this.data.xx +
				'&px=' + this.data.px +
				'&pg=' + this.data.pg + '&brandID=',
			success: (e) => {
				console.log(e)
				let a = this.data.data
				if (this.data.xin == 1) {
					a = []
				}
				for (let i in e.data.data) {
					a.push(e.data.data[i])
				}
				if (e.data.data.length < 15) {
					this.setData({
						pd: 0
					})
				}
				this.setData({
					data: a,
					xin: 0
				})
			}
		})
	},
	ovo() {
		if (this.data.pd == 1) {
			this.setData({
				pg: this.data.pg + 1
			})
			if (this.data.state == 0) {
				this.push()
			} else {
				this.dp()
			}
		}
	},
	xl() {
		this.setData({
			px: 3,
			data: [],
			pg:1,
		})
		this.push()
	},
	jiage() {
		if (this.data.px == 2) {
			this.setData({
				px: 1,
				pg:1,
				data: []
			})
			this.push()
		} else {
			this.setData({
				px: 2,
				pg:1,
				data: []
			})
			this.push()
		}
	}
})
